<!DOCTYPE html>
<html>
  <head>
    {include file="common/meta" /}
  </head>
  <body>
    <div class="x-body">
      <xblock>
        <button class="layui-btn layui-btn-danger" onclick="delAll()">
          <i class="layui-icon"></i>批量删除
        </button>
        <a href="{:url('admin/admin/add')}" class="layui-btn"><i class="layui-icon"></i>添加</a>
        <span class="x-right" style="line-height:40px">共有数据：{$count} 条</span>
      </xblock>
      <table class="layui-table">
        <thead>
          <tr>
            <th>
              <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th>登录名</th>
            <th>昵称</th>
            <th>状态</th>
            <th>操作</th>
        </thead>
        <tbody>
          {foreach $adminlist as $item}
          <tr>
            <td>
              <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='{$item.id}'><i class="layui-icon">&#xe605;</i></div>
            </td>
            <td>{$item.username}</td>
            <td>{$item.nickname}</td>
            <td class="td-status">
              {$item.state_text}
            <td class="td-manage">
              <a title="编辑" href="{:url('admin/Admin/edit',['adminid'=>$item['id']])}">
                <i class="layui-icon">&#xe642;</i>
              </a>
              <a title="删除" onclick="member_del(this,'{$item.id}')" href="javascript:;">
                <i class="layui-icon">&#xe640;</i>
              </a>
            </td>
          </tr>
          {/foreach}
        </tbody>
      </table>
      <div class="page">
        {$pagestr}
      </div>

    </div>
    
  </body>
</html>
<script>
  // 单个删除
  function member_del(obj,id){
    layer.confirm('确认要删除吗？',function(admin){
      del(id)
    });
  }

  // 批量删除
  function delAll(argument)
  {
    var data = tableCheck.getData();
    layer.confirm('确认要删除吗？',function(admin){
      // 讲数组转换为字符串
      var ids = data.join(',')
      del(ids)
    });
  }

  // 删除的异步请求
  function del(data)
  {
    // 序列化 将对象转换为参数形式
    var params = {
      ids:data
    }

    params = $.param(params)

    $.ajax({
      url:`{:url('admin/admin/del')}`,
      type:'post',
      data:params,
      dataType:'json',
      success:function(success)
      {
        layer.msg(success.msg,{icon:5,time:1000},function(){
          location.reload()
        })
      }
    })
  }
</script>